<!-- 提交申请 -->
<script lang="ts" setup>
import { ref, reactive, onMounted, h, watch } from 'vue'
import {
  NSpace,
  NButton,
  type FormInst,
  NForm,
  NFormItem,
  NInput,
  NProgress,
  NSelect,
  type FormRules,
  useMessage,
  NScrollbar,
  NSpin,
  NDatePicker,
  NUpload,
  NDataTable,
  type DataTableColumns,
  NModal,
  type UploadFileInfo,
  NPagination,
  NIcon,
  NTag
} from 'naive-ui'
import { sendRequest } from '@/utils/api'
import FixedAction from '@/components/FixedAction.vue'
import { keysOf } from '@/utils/object'
import VDialogContent from '@/views/OA/Common/DialogContent.vue'
import UploadFileV2 from '@/views/common/UploadFileV2.vue'
import TableView from '@/components/TableView.vue'
import { useThingStore } from '@/stores/addThing'
import VDisOrEnd from '@/views/OA/Common/DisOrEnd.vue'
import { useRoute } from 'vue-router'
import VScope from '@/views/OA/Common/Scope.vue'
import { ApprovalFilled, ErrorRound, AddCircleFilled } from '@vicons/material'
import { usePermissionStore } from '@/stores/permission'
import useRouteReplace from '@/hooks/useRouteReplace'
const props = defineProps({
  id: { type: String, default: () => null },
  typeShow: { type: Number, default: () => 0 },
  arr: { type: Array, default: () => 0 }
})
const permissionStore = usePermissionStore()
const route = useRoute()
const routeReplace = useRouteReplace(route.query.redirect as string)

const thingStore = useThingStore()
const rowKey: any = (row: any) => row.subItemCode || ''
const rowKeys = ref([])
const tableData: any = ref([])
const tableData1 = ref()
const message = useMessage()
const baseFormRef = ref<FormInst | null>(null)
const loading = ref(false)
const form: any = reactive({
  orderTypeCode: null,
  backOrder: {
    //回库单
    backDate: null, //回库日期
    backNumber: null, //回库单号
    fileIds: null, //附件
    humidity: null, // 保管相对湿度
    notes: null, //保管注意事项
    receiveUser: null, //接收人
    temperature: null, // 保管适宜温度
    transferUser: null //移交人
  },
  cancelOrder: {
    //注销单
    cancelDate: null, //注销日期
    cancelName: null, //注销凭证名称
    cancelNumber: null, //注销编号
    docNumber: null, //注销批准文号
    fileIds: null, //附件ids
    notes: null, //备注
    reason: null //注销原因
  },
  cleanOrder: {
    //消毒单
    cleanDate: null, //清洗消毒日期
    cleanName: null, //清洗消毒单名称
    cleanNumber: null, //清洗消毒单号
    cleanUser: null, //清洗消毒负责人
    fileIds: null, //附件ids
    notes: null //备注
  },
  damagedOrder: {
    //受损单
    damagedName: null, //单据名称
    damagedNumber: null, //保护修复单号
    fileIds: null, //附件ids
    notes: null //备注
  },
  moveOrder: {
    //移库单
    fileIds: null, //附件ids
    humidity: null, //保管相对湿度
    moveDate: null, //移库日期
    moveDept: null, //移动部门
    moveNumber: null, //移动单号
    moveUser: null, //移动人
    notes: null, //保管注意事项
    reason: null, //移动原因
    temperature: null //保管适宜温度
  },
  outOrder: {
    //出库单
    destinationCode: null, //去向
    exhibition: null, //展陈
    extractReason: null, //提取原因
    extractUnit: null, //提取部门
    extractUser: null, //提取人
    fileIds: null, //附件ids
    outDate: null, //出库日期
    outNumber: null, //出库单号
    ratifyNo: null, //批准文号
    returnDate: null //归还日期
  },
  repairOrder: {
    destinationCode: null, //去向
    fileIds: null, //附件ids
    notes: null, //备注
    repairDate: null, //保护修复日期
    repairName: null, //保护修复单标题
    repairNumber: null, //保护修复单号
    repairTypeCode: null //保护修复类型
  },
  subItemCodeList: null //工单类型
})
const paginationReactive = reactive({
  page: 1,
  pageSize: 10,
  showSizePicker: true,
  pageSizes: [10, 20, 50, 100, 500],
  itemCount: 0,
  onChange: (page: number) => {
    paginationReactive.page = page
    queryTableData()
  },
  onUpdatePageSize: (pageSize: number) => {
    paginationReactive.pageSize = pageSize
    paginationReactive.page = 1
    queryTableData()
  }
})
const columns: DataTableColumns = [
  {
    type: 'selection',
    width: '1rem'
  },
  {
    title: '藏品名称',
    key: 'itemName',
    width: '5rem',
    align: 'center'
  },
  {
    title: '流水号',
    key: 'serialNumber',
    width: '5rem',
    align: 'center'
  },
  {
    title: '资产码',
    key: 'assetCode',
    width: '5rem',
    align: 'center'
  },
  {
    title: '征集方式',
    key: 'collectTypeName',
    width: '10rem',
    align: 'center'
  },
  {
    title: '版本类型',
    key: 'itemTypeName',
    width: '10rem',
    align: 'center'
  },
  {
    title: '入库位置',
    key: 'positionName',
    width: '10rem',
    align: 'center'
  },
  {
    title: '操作',
    key: 'action',
    width: '10rem',
    align: 'center',
    fixed: 'right',
    render: (e: any) => [
      h(
        NButton,
        {
          type: 'primary',
          quaternary: true,
          style: {
            color: 'red'
          },
          onClick: () => {
            deleteIdOnly.value = e.subItemCode
            type.value = true
            modalVisible.value = true
          }
        },
        {
          default: () => '删除'
        }
      )
    ]
  }
]
const modalVisiblePosition = ref(false)
const optionInPosition0 = ref([])
const optionInPosition1 = ref([])
const optionInPosition2 = ref([])
const optionInPosition3 = ref([])
const optionInPosition4 = ref([])
const optionInPosition5 = ref([])
const getFirstFn = async (id: any, refValue: any) => {
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'listOptionsByParentId',
    override: {
      params: {
        parentId: id
      }
    }
  })
  if (error) return message.error(error.message)
  refValue.value = res?.data || []
}
const getLevel = (name: string) => (name ? ' > ' + name : '')
const columns1: DataTableColumns = [
  {
    type: 'selection',
    width: '1rem'
  },
  {
    title: '藏品名称',
    key: 'itemName',
    width: '5rem',
    align: 'center'
  },
  {
    title: '流水号',
    key: 'serialNumber',
    width: '5rem',
    align: 'center'
  },
  {
    title: '资产码',
    key: 'assetCode',
    width: '5rem',
    align: 'center'
  },
  {
    title: '征集方式',
    key: 'collectTypeName',
    width: '10rem',
    align: 'center'
  },
  {
    title: '版本类型',
    key: 'itemTypeName',
    width: '10rem',
    align: 'center'
  },
  {
    title: '入库位置',
    key: 'positionName',
    width: '15rem',
    align: 'center'
  },
  {
    title: '移库位置',
    key: 'relocationLocation',
    width: '15rem',
    align: 'center',
    render: (e: any) => {
      return h(
        'div',
        {
          style: {
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'space-between'
          }
        },
        [
          h('div', { width: '100rem' }, e.relocationLocation || '请选择库房位置'),
          h(AddCircleFilled, {
            style: {
              width: '20px',
              height: '20px',
              float: 'right'
            },
            onClick: async () => {
              deleteIdOnly.value = e.subItemCode
              form.itemsStaging = { ...e.itemsStaging }
              await getFirstFn(e?.itemsStaging?.firstLevelCode, optionInPosition1)
              await getFirstFn(e?.itemsStaging?.secondLevelCode, optionInPosition2)
              await getFirstFn(e?.itemsStaging?.threeLevelCode, optionInPosition3)
              await getFirstFn(e?.itemsStaging?.fourthLevelCode, optionInPosition4)
              await getFirstFn(e?.itemsStaging?.fifthLevelCode, optionInPosition5)
              modalVisiblePosition.value = true
            }
          })
        ]
      )
    }
  },
  {
    title: '操作',
    key: 'action',
    width: '10rem',
    align: 'center',
    fixed: 'right',
    render: (e: any) => [
      h(
        NButton,
        {
          type: 'primary',
          quaternary: true,
          style: {
            color: 'red'
          },
          onClick: () => {
            deleteIdOnly.value = e.subItemCode
            type.value = true
            modalVisible.value = true
          }
        },
        {
          default: () => '删除'
        }
      )
    ]
  }
]
const formRules: FormRules = {
  backOrder: {
    //回库单
    backDate: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    }, //回库日期
    backNumber: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //回库单号
    // humidity: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // }, // 保管相对湿度
    receiveUser: {
      required: true,
      trigger: ['blur', 'input', 'change'],
      type: 'any',
      message: '不能为空'
    }, //保管注意事项
    // temperature: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // }, // 保管适宜温度
    transferUser: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    } //移交人
  },
  cancelOrder: {
    //注销单
    cancelDate: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    }, //注销日期
    cancelName: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //注销凭证名称
    cancelNumber: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //注销编号
    reason: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    } //注销原因
    // docNumber: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // } //注销批准文号
  },
  cleanOrder: {
    //消毒单
    cleanDate: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    }, //清洗消毒日期
    cleanName: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //清洗消毒单名称
    cleanNumber: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //清洗消毒单号
    cleanUser: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    } //清洗消毒负责人
  },
  damagedOrder: {
    //受损单
    damagedName: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //单据名称
    damagedNumber: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    } //保护修复单号
  },
  moveOrder: {
    //移库单
    // humidity: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // }, //保管相对湿度
    moveDate: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    }, //移库日期
    moveDept: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //移动部门
    moveNumber: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //移动单号
    moveUser: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //移动人
    reason: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    } //移动原因
    // temperature: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // } //保管适宜温度
  },
  outOrder: {
    //出库单
    destinationCode: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    }, //去向
    extractReason: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //提取原因
    // extractUnit: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // }, //提取部门
    // extractUser: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // }, //提取人
    outDate: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    }, //出库日期
    outNumber: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //出库单号
    // ratifyNo: {
    //   required: true,
    //   trigger: ['blur', 'input'],
    //   type: 'any',
    //   message: '不能为空'
    // }, //批准文号
    returnDate: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    } //归还日期
  },
  repairOrder: {
    // destinationCode: {
    //   required: true,
    //   trigger: ['blur', 'change'],
    //   type: 'any',
    //   message: '不能为空'
    // }, //去向
    repairDate: {
      required: true,
      trigger: ['blur', 'change'],
      type: 'any',
      message: '不能为空'
    }, //保护修复日期
    repairName: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    }, //保护修复单标题
    repairNumber: {
      required: true,
      trigger: ['blur', 'input'],
      type: 'any',
      message: '不能为空'
    } //保护修复单号
    // repairTypeCode: {
    //   required: true,
    //   trigger: ['blur', 'change'],
    //   type: 'any',
    //   message: '不能为空'
    // } //保护修复类型
  }
}
const tableLoading = ref()
const queryTableData = async (resetPage = false) => {
  if (resetPage) paginationReactive.page = 1
  tableLoading.value = true
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'userOrderCollectItem',
    override: {
      params: {
        page: paginationReactive.page,
        limit: paginationReactive.pageSize
      }
    }
  })
  if (error) return message.error(error.message)
  const tmp: any = res.data
  tableData.value = res.data.list
  paginationReactive.itemCount = res.data.totalCount
  tableLoading.value = false
}
const percentage = ref(0)
const processVisible = ref(false)
const timer = ref<number | null>(null)
  const importErrorModalVisible = ref(false)
const importErrorMessage = ref('')
const importErrorExcelPath = ref('')
const isImportSuccess = ref(false)
const handleCancelImport = () => {
  importErrorModalVisible.value = false
}
const handleExport = () => {
  if (importErrorExcelPath.value) {
    const a = document.createElement('a')
    a.href = importErrorExcelPath.value
    a.download = '导入错误.xlsx'
    a.click()
  }
  importErrorModalVisible.value = false
}
const sendUpload = async (resetPage = false, file: any) => {
  if (resetPage) paginationReactive.page = 1
  processVisible.value = true
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'importCollectingItemsOfOrder',
    override: {
      data: {
        file: file,
        code: form.orderTypeCode == 'A3503' ? 2 : 1 //1 其他 2 移库
      },
      onUploadProgress: (e: any) => {
        console.log(e.progress, e.loaded, e.total)
        const complete = Math.round((e.loaded * 100) / e.total)
        // percentage.value = Math.round((e.loaded * 100) / e.total)
        // 超过80 开始干涉
        if (complete >= 80) {
          if (timer.value) return
          timer.value = window.setInterval(() => {
            percentage.value += Math.round((100 - percentage.value) * 0.2) // 每次增加剩下的20%

            // 超过99 不再变化（此时也接近上传完成了）
            if (percentage.value > 99) {
              timer.value && window.clearInterval(timer.value)
            }
          }, 1000)
        } else {
          // 在80之前都按照axios计算出的进度来显示
          percentage.value = complete
        }
      }
    }
  })
  loading.value = false
  if (error) return message.error(error.message)
  percentage.value = 100
  // 100加载完成再关闭进度条
  setTimeout(() => {
    console.log('结束')
  }, 500)
  timer.value && window.clearInterval(timer.value)
  processVisible.value = false
  if (res.code !== 0) return message.error(res.msg)
  message.success(res.data)
  isImportSuccess.value = res.data?.trueFlag
  importErrorMessage.value = res?.data.errorInfo
  importErrorExcelPath.value = res?.data.excelPath
  importErrorModalVisible.value = true
  getWorkFlowImport()
  queryTableData()
}

async function handleUploadChange(fileList: UploadFileInfo[]) {
  form.file = fileList[fileList.length - 1]?.file
  sendUpload(false, fileList[fileList.length - 1]?.file)
}
// 设置默认值
const setTranslateName = async () => {
  const [error, res] = await sendRequest({
    module: 'user',
    api: 'permissionInfo',
    uri: {
      userId: permissionStore.userInfo?.id!
    }
  })
  if (error) return message.error(error.message)
  form.backOrder.transferUser = res.data?.userName
  form.outOrder.extractUser = res.data?.userName
  form.outOrder.extractUnit = res.data?.deptName
  form.moveOrder.moveUser = res.data?.userName
}
//下载
function download(headers: any, data: any, name?: string) {
  const val = headers['content-disposition']?.match(/(?<=filename=)(.*)/)
  let filename = val ? decodeURIComponent(val[0]) : name + '导出.xlsx'
  if (!filename.includes('xlsx')) {
    filename = filename.replace('xls', 'xlsx')
  }
  const a = document.createElement('a')
  let binaryData = []
  binaryData.push(data)
  a.href = window.URL.createObjectURL(new Blob(binaryData))
  a.download = filename
  a.click()
  window.URL.revokeObjectURL(a.href)
}
async function handleDownload() {
  const [error, res, headers] = await sendRequest({
    module: 'collectProcess',
    api: 'downloadTemplateOfOrder',
    override: {
      params: {
        code: form.orderTypeCode == 'A3503' ? 2 : 1 //1 其他 2 移库
      }
    }
  })
  if (error) return message.error(error.message)
  download(headers, res)
}
const contactsModalVisible = ref(false)
const handleDeleteContact = (index: number, type: any) => {
  if (type == 1) {
    //回库单
    form.backOrder.batchReceivers.splice(index, 1)
    form.backOrder.receiveUser = form.backOrder.batchReceivers.map((e: any) => e.typeName).join(',')
  } else {
    form.cleanOrder.batchReceivers.splice(index, 1)
    form.cleanOrder.cleanUser = form.cleanOrder.batchReceivers.map((e: any) => e.typeName).join(',')
  }
}
const handleContactsModalSubmit = (v: any[]) => {
  if (form.orderTypeCode == 'A3502') {
    //回库单
    form.backOrder.batchReceivers = v
    form.backOrder.receiveUser = v.map((e) => e.typeName).join(',')
  } else {
    //消毒
    form.cleanOrder.batchReceivers = v
    form.cleanOrder.cleanUser = v.map((e) => e.typeName).join(',')
  }
  contactsModalVisible.value = false
}

const deleteIdOnly = ref(null) //删除的id
const type = ref(false)
const againDelete = async () => {
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'collectingItemUserOrderTemporaryDelete',
    override: {
      data: !type.value ? deleteId.value : [deleteIdOnly.value]
    }
  })
  if (error) return message.error(error.message)
  message.success(res.data)
  modalVisible.value = false
  deleteId.value = []
  getWorkFlowImport()
  queryTableData()
  document.dispatchEvent(new Event('sqgd-refresh'))
}
const handleUpdateFileList = (e: UploadFileInfo[], name: any) => {
  form[name].fileIdFiles = e
  // @ts-ignore
  form[name].fileIds = e.map((it) => it.file?.remoteId).join(',')
}
const configData: any = ref([])
const otherConfigData: any = ref([])
const getOptionFn = async () => {
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'countCollectingByType'
  })
  if (error) return message.error(error.message)
  configData.value = res?.data.slice(0, 6)
  otherConfigData.value = res.data?.slice(6)
}
const entityId = ref()

const submit = async () => {
  const validate = await Promise.all([
    new Promise((resolve, reject) => {
      baseFormRef.value?.validate((error) => {
        if (error) return reject(error)
        resolve(true)
      })
    })
  ])

  if (!validate.every(Boolean)) return
  loading.value = true
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'collectingOrderCommitOrder',
    override: {
      data: {
        ...form,
        entityId: entityId.value,
        subItemCodeList: tableData.value?.map((it: any) => it.subItemCode)
      }
    }
  })
  loading.value = false

  if (error) return message.error(error.message)
  if (res.code !== 0) return message.error(res.msg)
  message.success(res.msg)
  const [error1, res1] = await sendRequest({
    module: 'collectProcess',
    api: 'collectingItemUserOrderTemporaryDelete',
    override: {
      data: tableData.value?.map((it: any) => it.subItemCode)
    }
  })
  if (error1) return message.error(error1.message)
  if (res1.code !== 0) return message.error(res1.msg)
  // window.flags.flushManageProcessTable = true
  goBack()
}
const changePositionName = async () => {
  if (!form.itemsStaging.firstLevelName) return
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'updateRelocationLocation',
    override: {
      data: {
        ...form.itemsStaging,
        subItemCode: deleteIdOnly.value
      }
    }
  })
  loading.value = false

  if (error) return message.error(error.message)
  if (res.code !== 0) return message.error(res.msg)
  message.success(res.msg)
  modalVisiblePosition.value = false
  queryTableData()
}
const changeOptionFn = (e: any, type: any, option: any) => {
  console.log(option, '222')

  switch (type) {
    case 1: {
      form.itemsStaging.firstLevelName = option?.label
      form.itemsStaging.secondLevelName = null
      form.itemsStaging.threeLevelName = null
      form.itemsStaging.fourthLevelName = null
      form.itemsStaging.fifthLevelName = null
      form.itemsStaging.sixthLevelName = null
      form.itemsStaging.secondLevelCode = null
      form.itemsStaging.threeLevelCode = null
      form.itemsStaging.fourthLevelCode = null
      form.itemsStaging.fifthLevelCode = null
      form.itemsStaging.sixthLevelCode = null
      getFirstFn(e, optionInPosition1)
      break
    }
    case 2: {
      form.itemsStaging.secondLevelName = option?.label
      form.itemsStaging.threeLevelName = null
      form.itemsStaging.fourthLevelName = null
      form.itemsStaging.fifthLevelName = null
      form.itemsStaging.sixthLevelName = null
      form.itemsStaging.threeLevelCode = null
      form.itemsStaging.fourthLevelCode = null
      form.itemsStaging.fifthLevelCode = null
      form.itemsStaging.sixthLevelCode = null
      getFirstFn(e, optionInPosition2)
      break
    }
    case 3: {
      form.itemsStaging.threeLevelName = option?.label
      form.itemsStaging.fourthLevelName = null
      form.itemsStaging.fifthLevelName = null
      form.itemsStaging.sixthLevelName = null
      form.itemsStaging.fourthLevelCode = null
      form.itemsStaging.fifthLevelCode = null
      form.itemsStaging.sixthLevelCode = null
      getFirstFn(e, optionInPosition3)
      break
    }
    case 4: {
      form.itemsStaging.fourthLevelName = option?.label
      form.itemsStaging.fifthLevelName = null
      form.itemsStaging.sixthLevelName = null
      form.itemsStaging.fifthLevelCode = null
      form.itemsStaging.sixthLevelCode = null
      getFirstFn(e, optionInPosition4)
      break
    }
    case 5: {
      form.itemsStaging.fifthLevelName = option?.label
      form.itemsStaging.sixthLevelName = null
      form.itemsStaging.sixthLevelCode = null
      getFirstFn(e, optionInPosition5)
      break
    }
  }
}
// 字典下拉
const codeFn = async (code: any, refValue: any) => {
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'listByParentCode',
    override: {
      params: {
        dicCode: code
      }
    }
  })
  if (error) return message.error(error.message)
  refValue.value = res?.data?.map((it: any) => {
    return { value: it.dicCode, label: it.dicName }
  })
  if (code == 'A35') {
    form.orderTypeCode = res?.data?.[0]?.dicCode
  }
}
// 获取流程id
const hint = ref()
const workFlowList: any = ref()
const importBoolean = ref()
const getWorkFlowImport = async () => {
  form.backOrder.batchReceivers = []
  form.backOrder.receiveUser = null
  form.cleanOrder.batchReceivers = []
  form.cleanOrder.cleanUser = null
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'checkImportantTag'
  })
  if (error) return
  if (res.code !== 0) return
  importBoolean.value = res.data
  getWorkFlow(form.orderTypeCode)
}
const getWorkFlow = async (e: any) => {
  form.backOrder.batchReceivers = []
  form.backOrder.receiveUser = null
  form.cleanOrder.batchReceivers = []
  form.cleanOrder.cleanUser = null
  const [error, res] = await sendRequest({
    module: 'collectProcess',
    api: 'getOrderWorkFlow',
    override: {
      data: {
        orderTypeCode: e,
        flag: importBoolean.value
      }
    }
  })
  if (error) return
  if (res.code !== 0) return
  entityId.value = res.data.entityId
  hint.value = res.data.remark
  workFlowList.value = res.data.workFlowList?.map((it: any) => it).join(' → ')
}
const statusList = ref()
const statusList31 = ref()
const statusList30 = ref()
const flat: any = ref(false)
watch(
  () => route.path,
  () => {
    if (route.path == '/collection/process/ManageProcess/submitFile') {
      queryTableData(true)
      setTranslateName()
      if (!props.id && props.id != 0) {
        codeFn('A35', statusList)
        form.outOrder.destinationCode = null
        form.outOrder.exhibition = null
        form.outOrder.extractReason = null
        form.outOrder.extractUnit = null
        form.outOrder.extractUser = null
        form.outOrder.fileIds = null
        form.outOrder.outDate = null
        form.outOrder.outNumber = null
        form.outOrder.ratifyNo = null
        form.outOrder.returnDate = null
        form.outOrder.fileIdFiles = []
      }
    }
    if (route.query.flat) flat.value = route.query.flat
  },
  { deep: true, immediate: true }
)
// 返回
const goBack = () => {
  window.flags.flushManageProcessTable = true
  // history.back()
  routeReplace()
}

const deleteId = ref([])
const modalVisible = ref(false)
const rowKeysChange = (v: any) => {
  deleteId.value = v
}
const BatchDelete = () => {
  if (deleteId.value?.length === 0) return message.warning('请至少选择一项！')
  type.value = false
  modalVisible.value = true
}

const dateDisabledBefore = (ts: any, data: any) => {
  if (data) {
    let time = new Date(data).getTime()
    return ts > time
  }
  return false
}
const dateDisabledAfter = (ts: number, data: any) => {
  let time = new Date(data).getTime()
  return ts < time - 86400000
}
const editId: any = ref()
onMounted(async () => {
  await codeFn('A35', statusList) //审批清单 A35
  codeFn('A57', statusList31) //保护修复类型,关联字典A31
  codeFn('A36', statusList30) //去向,关联字典A36
  getWorkFlowImport()
  getOptionFn()
  queryTableData()
  await getFirstFn(0, optionInPosition0)
  //出库单 A3501 回库单 A3502 移库单 A3503 消毒单 A3504  修复单 A3505 受损单 A3506  注销单 A3507
  // if (thingStore.thingList) {
  //   let dataArr = dataTrue.value
  //   dataTrue.value = dataArr.concat(thingStore.thingList)
  //   editId.value = props.id
  //   tableData.value = dataTrue.value?.slice(0, 10)
  //   thingStore.thingList = []
  // }
  // 修改回显
  if (props?.id) {
    sendRequest({
      module: 'collectProcess',
      api: 'orderBaseInfo',
      override: {
        params: {
          id: props?.id
        }
      }
    }).then(async ([err, res]) => {
      if (err) return
      keysOf(res.data).forEach((e) => {
        form[e] = res.data[e] as never
      })
      tableData1.value = res.data?.workflowInfoVo?.approvalRecordsList || []
    })
  }
})
</script>

<template>
  <div class="main">
    <div class="form_content">
      <NScrollbar>
        <NSpin :show="false">
          <div class="content">
            <div v-if="!editId">
              <!-- <div class="topTitle" style="margin-bottom: 10px;">审核流程</div>
              <div style="height: 10px;">

              </div>
              <span class="bd-card" style="color: #79bb92; font-size: 18rem; margin-left: 0rem">
                {{ workFlowList?.length ? workFlowList : '暂无适配流程' }}
              </span>
              <div style="height: 10px;">

              </div> -->
              <div
                class="progressHint"
                v-if="hint"
              >
                <NIcon
                  size="20"
                  class="iconStyle"
                >
                  <ErrorRound />
                </NIcon>
                <div
                  style="white-space: pre-wrap"
                  v-html="hint"
                ></div>
              </div>
              <div class="progress">
                <div style="display: flex; width: auto; padding: 0 15px">
                  <NIcon
                    :size="20"
                    class="iconStyle"
                  >
                    <ApprovalFilled />
                  </NIcon>
                  <span>审批流程</span>
                </div>
                <span
                  style="font-size: 18rem; flex: 1"
                  :style="{ color: !workFlowList ? 'red' : '#79bb92' }"
                >
                  {{ workFlowList ? workFlowList : '暂无配置流程，请联系管理员进行配置' }}
                </span>
              </div>
              <!-- <basicInfo :id="props?.code"/> -->
              <NSpace style="margin-top: 20rem">
                <!-- 审批清单 -->
                <span style="font-size: 16rem">选择发起审批的清单:</span>
                <NSelect
                  :options="statusList"
                  v-model:value="form.orderTypeCode"
                  placeholder="图书"
                  class="inputWH"
                  @update-value="getWorkFlow"
                />
              </NSpace>
            </div>
            <VDisOrEnd
              v-if="flat"
              :id="form.workflowInfoVo?.fromId"
              :assigneeFlag="form.workflowInfoVo?.assigneeFlag"
              typeName="工单审批"
            ></VDisOrEnd>
            <div class="topTitle">基本信息</div>
            <div>
              <DetailFormProvider :disabled="editId === null && editId === undefined">
                <!-- 出库单 1-->
                <NForm
                  :model="form"
                  class="bd-card"
                  :rules="formRules"
                  ref="baseFormRef"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140"
                  :disabled="editId"
                  v-if="form.orderTypeCode == 'A3501'"
                >
                  <NFormItem
                    label="出库单号："
                    path="outOrder.outNumber"
                    v-if="editId"
                  >
                    <NInput
                      v-model:value="form.outOrder.outNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="出库日期："
                    path="outOrder.outDate"
                  >
                    <NDatePicker
                      placeholder="请选择日期"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :is-date-disabled="(e: any) => dateDisabledBefore(e, form.outOrder.returnDate)"
                      v-model:formatted-value="form.outOrder.outDate"
                      :input-readonly="true"
                      class="inputWH"
                      clearable
                    />
                  </NFormItem>
                  <NFormItem
                    label="归还日期："
                    path="outOrder.returnDate"
                  >
                    <NDatePicker
                      placeholder="请选择日期"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :is-date-disabled="(e: any) => dateDisabledAfter(e, form.outOrder.outDate)"
                      v-model:formatted-value="form.outOrder.returnDate"
                      :input-readonly="true"
                      class="inputWH"
                      clearable
                    />
                  </NFormItem>
                  <NFormItem
                    label="提取部门："
                    path="outOrder.extractUnit"
                  >
                    <NInput
                      v-model:value="form.outOrder.extractUnit"
                      class="inputWH"
                      disabled
                    />
                  </NFormItem>
                  <NFormItem
                    label="提取人："
                    path="outOrder.extractUser"
                  >
                    <NInput
                      v-model:value="form.outOrder.extractUser"
                      class="inputWH"
                      disabled
                    />
                  </NFormItem>
                  <NFormItem
                    label="批准文号："
                    path="outOrder.ratifyNo"
                  >
                    <NInput
                      v-model:value="form.outOrder.ratifyNo"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="去向："
                    path="outOrder.destinationCode"
                  >
                    <NSelect
                      :options="statusList30"
                      v-model:value="form.outOrder.destinationCode"
                      placeholder="去向"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="提取原因："
                    path="outOrder.extractReason"
                  >
                    <NInput
                      v-model:value="form.outOrder.extractReason"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="展陈："
                    path="outOrder.exhibition"
                    v-if="form.outOrder.destinationCode == 'A3601'"
                  >
                    <NInput
                      v-model:value="form.outOrder.exhibition"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="附件："
                    path="outOrder.fileIds"
                  >
                    <UploadFileV2
                      :file-list="form.outOrder.fileIdFiles"
                      @update:file-list="(e: any) => handleUpdateFileList(e, 'outOrder')"
                    >
                      <template #trigger="{ handleClick }">
                        <n-button
                          @click="handleClick"
                          color="#6CB187"
                          ghost
                          size="small"
                        >
                          点击上传
                        </n-button>
                      </template>
                    </UploadFileV2>
                    <!-- <NUpload style="padding-top: 5px">
                    <NButton
                      color="#6CB187"
                      ghost
                      size="small"
                    >
                      点击上传
                    </NButton>
                  </NUpload> -->
                  </NFormItem>
                </NForm>
                <!-- 回库单-->
                <NForm
                  :model="form"
                  class="bd-card"
                  :rules="formRules"
                  ref="baseFormRef"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140"
                  :disabled="editId"
                  v-if="form.orderTypeCode == 'A3502'"
                >
                  <NFormItem
                    label="回库编号："
                    path="backOrder.backNumber"
                    v-if="editId"
                  >
                    <NInput
                      v-model:value="form.backOrder.backNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="回库日期："
                    path="backOrder.backDate"
                  >
                    <NDatePicker
                      placeholder="请选择日期"
                      type="date"
                      value-format="yyyy-MM-dd"
                      class="inputWH"
                      v-model:formatted-value="form.backOrder.backDate"
                      :input-readonly="true"
                      clearable
                    />
                  </NFormItem>
                  <NFormItem
                    label="移交人："
                    path="backOrder.transferUser"
                  >
                    <NInput
                      v-model:value="form.backOrder.transferUser"
                      class="inputWH"
                      disabled
                    />
                  </NFormItem>
                  <NFormItem
                    label="接收人："
                    path="backOrder.receiveUser"
                  >
                    <div class="contacts">
                      <NButton
                        type="primary"
                        ghost
                        @click="contactsModalVisible = true"
                      >
                        选择接收人
                      </NButton>
                      <NScrollbar style="max-height: 120rem">
                        <div
                          v-show="form.backOrder.batchReceivers?.length"
                          class="contacts-content"
                        >
                          <NTag
                            v-for="(contact, index) in form.backOrder.batchReceivers"
                            @close="handleDeleteContact(index, 1)"
                            :key="index"
                            :color="{ color: '#ffffff' }"
                            closable
                            style="justify-content: space-between; gap: 0 10rem"
                          >
                            {{ contact.typeName }}
                          </NTag>
                        </div>
                      </NScrollbar>
                    </div>
                    <!-- <NInput
                        v-model:value="form.backOrder.receiveUser"
                        class="inputWH"
                      /> -->
                  </NFormItem>
                  <NFormItem
                    label="保管适宜温度："
                    path="backOrder.temperature"
                  >
                    <NInput
                      v-model:value="form.backOrder.temperature"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="保管相对湿度："
                    path="backOrder.humidity"
                  >
                    <NInput
                      v-model:value="form.backOrder.humidity"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="保管注意事项："
                    path="backOrder.notes"
                  >
                    <NInput
                      v-model:value="form.backOrder.notes"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="附件："
                    path="backOrder.fileIds"
                  >
                    <UploadFileV2
                      :file-list="form.backOrder.fileIdFiles"
                      @update:file-list="(e: any) => handleUpdateFileList(e, 'backOrder')"
                    >
                      <template #trigger="{ handleClick }">
                        <n-button
                          @click="handleClick"
                          color="#6CB187"
                          ghost
                          size="small"
                        >
                          点击上传
                        </n-button>
                      </template>
                    </UploadFileV2>
                    <!-- <NUpload
                      style="padding-top: 5px"
                      v-model:value="form.backOrder.fileIds"
                    >
                      <NButton
                        color="#6CB187"
                        ghost
                        size="small"
                      >
                        点击上传
                      </NButton>
                    </NUpload> -->
                  </NFormItem>
                </NForm>
                <!-- 移库单-->
                <NForm
                  :model="form"
                  :rules="formRules"
                  ref="baseFormRef"
                  class="bd-card"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140"
                  :disabled="editId"
                  v-if="form.orderTypeCode == 'A3503'"
                >
                  <NFormItem
                    label="移库编号："
                    v-if="editId"
                    path="moveOrder.moveNumber"
                  >
                    <NInput
                      v-model:value="form.moveOrder.moveNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="移库日期："
                    path="moveOrder.moveDate"
                  >
                    <NDatePicker
                      placeholder="请选择日期"
                      type="date"
                      value-format="yyyy-MM-dd"
                      v-model:formatted-value="form.moveOrder.moveDate"
                      :input-readonly="true"
                      class="inputWH"
                      clearable
                    />
                  </NFormItem>
                  <!-- <NFormItem
                      label="移动部门："
                      path="moveOrder.moveDept"
                    >
                      <NInput
                        v-model:value="form.moveOrder.moveDept"
                        class="inputWH"
                      />
                    </NFormItem> -->
                  <NFormItem
                    label="移动人："
                    path="moveOrder.moveUser"
                  >
                    <NInput
                      v-model:value="form.moveOrder.moveUser"
                      class="inputWH"
                      disabled
                    />
                  </NFormItem>
                  <NFormItem
                    label="移动原因："
                    path="moveOrder.reason"
                  >
                    <NInput
                      v-model:value="form.moveOrder.reason"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="保管适宜温度："
                    path="moveOrder.temperature"
                  >
                    <NInput
                      v-model:value="form.moveOrder.temperature"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="保管相对湿度："
                    path="moveOrder.humidity"
                  >
                    <NInput
                      v-model:value="form.moveOrder.humidity"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="保管注意事项："
                    path="moveOrder.notes"
                  >
                    <NInput
                      v-model:value="form.moveOrder.notes"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="附件："
                    path="moveOrder.fileIds"
                  >
                    <UploadFileV2
                      :file-list="form.moveOrder.fileIdFiles"
                      @update:file-list="(e: any) => handleUpdateFileList(e, 'moveOrder')"
                    >
                      <template #trigger="{ handleClick }">
                        <n-button
                          @click="handleClick"
                          color="#6CB187"
                          ghost
                          size="small"
                        >
                          点击上传
                        </n-button>
                      </template>
                    </UploadFileV2>
                    <!-- <UploadFileV2
                  :default-file-list="form.fileList"
                  >
                  </UploadFileV2> -->
                  </NFormItem>
                </NForm>
                <!-- 消毒单-->
                <NForm
                  :model="form"
                  :rules="formRules"
                  ref="baseFormRef"
                  class="bd-card"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140"
                  :disabled="editId"
                  v-if="form.orderTypeCode == 'A3504'"
                >
                  <NFormItem
                    label="清洗消毒单号："
                    v-if="editId"
                    path="cleanOrder.cleanNumber"
                  >
                    <NInput
                      v-model:value="form.cleanOrder.cleanNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="清洗消毒单名称："
                    path="cleanOrder.cleanName"
                  >
                    <NInput
                      v-model:value="form.cleanOrder.cleanName"
                      class="inputWH"
                    />
                  </NFormItem>

                  <NFormItem
                    label="清洗消毒日期:"
                    path="cleanOrder.cleanDate"
                  >
                    <NDatePicker
                      placeholder="请选择日期"
                      type="date"
                      value-format="yyyy-MM-dd"
                      v-model:formatted-value="form.cleanOrder.cleanDate"
                      :input-readonly="true"
                      class="inputWH"
                      clearable
                    />
                  </NFormItem>
                  <NFormItem
                    label="清洗消毒负责人:"
                    path="cleanOrder.cleanUser"
                  >
                    <div class="contacts">
                      <NButton
                        type="primary"
                        ghost
                        @click="contactsModalVisible = true"
                      >
                        选择负责人
                      </NButton>
                      <NScrollbar style="max-height: 120rem">
                        <div
                          v-show="form.cleanOrder.batchReceivers?.length"
                          class="contacts-content"
                        >
                          <NTag
                            v-for="(contact, index) in form.cleanOrder.batchReceivers"
                            @close="handleDeleteContact(index, 2)"
                            :key="index"
                            :color="{ color: '#ffffff' }"
                            closable
                            style="justify-content: space-between; gap: 0 10rem"
                          >
                            {{ contact.typeName }}
                          </NTag>
                        </div>
                      </NScrollbar>
                    </div>
                    <!-- <NInput
                        v-model:value="form.cleanOrder.cleanUser"
                        class="inputWH"
                      /> -->
                  </NFormItem>
                  <NFormItem
                    label="备注:"
                    path="cleanOrder.notes"
                  >
                    <NInput
                      v-model:value="form.cleanOrder.notes"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="附件："
                    path="cleanOrder.fileIds"
                  >
                    <UploadFileV2
                      :file-list="form.cleanOrder.fileIdFiles"
                      @update:file-list="(e: any) => handleUpdateFileList(e, 'cleanOrder')"
                    >
                      <template #trigger="{ handleClick }">
                        <n-button
                          @click="handleClick"
                          color="#6CB187"
                          ghost
                          size="small"
                        >
                          点击上传
                        </n-button>
                      </template>
                    </UploadFileV2>
                    <!-- <NUpload
                      style="padding-top: 5px"
                      class="inputWH"
                    >
                      <NButton
                        color="#6CB187"
                        ghost
                        size="small"
                      >
                        点击上传
                      </NButton>
                    </NUpload> -->
                  </NFormItem>
                </NForm>
                <!-- 修复单-->
                <NForm
                  :model="form"
                  :rules="formRules"
                  class="bd-card"
                  ref="baseFormRef"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140"
                  :disabled="editId"
                  v-if="form.orderTypeCode == 'A3505'"
                >
                  <NFormItem
                    label="保护修复单号:"
                    path="repairOrder.repairNumber"
                    v-if="editId"
                  >
                    <NInput
                      v-model:value="form.repairOrder.repairNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="修复标题："
                    path="repairOrder.repairName"
                  >
                    <NInput
                      v-model:value="form.repairOrder.repairName"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="修复类型："
                    path="repairOrder.repairTypeCode"
                  >
                    <NSelect
                      :options="statusList31"
                      v-model:value="form.repairOrder.repairTypeCode"
                      placeholder="下拉单选框"
                      class="inputWH"
                    />
                  </NFormItem>

                  <!-- <NFormItem
                      label="去向："
                      path="repairOrder.destinationCode"
                    >
                      <NSelect
                        :options="statusList30"
                        v-model:value="form.repairOrder.destinationCode"
                        placeholder="下拉单选框"
                        class="inputWH"
                      />
                    </NFormItem> -->

                  <NFormItem
                    label="保护修复日期："
                    path="repairOrder.repairDate"
                  >
                    <NDatePicker
                      placeholder="请选择日期"
                      type="date"
                      value-format="yyyy-MM-dd"
                      v-model:formatted-value="form.repairOrder.repairDate"
                      :input-readonly="true"
                      class="inputWH"
                      clearable
                    />
                  </NFormItem>
                  <NFormItem
                    label="备注："
                    path="repairOrder.notes"
                  >
                    <NInput
                      v-model:value="form.repairOrder.notes"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="附件："
                    path="repairOrder.fileIds"
                  >
                    <UploadFileV2
                      :file-list="form.repairOrder.fileIdFiles"
                      @update:file-list="(e: any) => handleUpdateFileList(e, 'repairOrder')"
                    >
                      <template #trigger="{ handleClick }">
                        <n-button
                          @click="handleClick"
                          color="#6CB187"
                          ghost
                          size="small"
                        >
                          点击上传
                        </n-button>
                      </template>
                    </UploadFileV2>
                  </NFormItem>
                </NForm>
                <!-- 受损单 -->
                <NForm
                  :model="form"
                  :rules="formRules"
                  ref="baseFormRef"
                  class="bd-card"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140"
                  :disabled="editId"
                  v-if="form.orderTypeCode == 'A3506'"
                >
                  <NFormItem
                    label="保护修复单号："
                    path="damagedOrder.name"
                    v-if="editId"
                  >
                    <NInput
                      v-model:value="form.damagedOrder.damagedNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="名称："
                    path="damagedOrder.damagedName"
                  >
                    <NInput
                      v-model:value="form.damagedOrder.damagedName"
                      class="inputWH"
                    />
                  </NFormItem>

                  <NFormItem
                    label="备注："
                    path="damagedOrder.notes"
                  >
                    <NInput
                      v-model:value="form.damagedOrder.notes"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="附件："
                    path="moveOrder.name"
                  >
                    <UploadFileV2
                      :file-list="form.moveOrder.fileIdFiles"
                      @update:file-list="(e: any) => handleUpdateFileList(e, 'damagedOrder')"
                    >
                      <template #trigger="{ handleClick }">
                        <n-button
                          @click="handleClick"
                          color="#6CB187"
                          ghost
                          size="small"
                        >
                          点击上传
                        </n-button>
                      </template>
                    </UploadFileV2>
                  </NFormItem>
                </NForm>
                <!-- 注销单 -->
                <NForm
                  :model="form"
                  :rules="formRules"
                  class="bd-card"
                  ref="baseFormRef"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140"
                  :disabled="editId"
                  v-if="form.orderTypeCode == 'A3507'"
                >
                  <NFormItem
                    label="注销编号:"
                    v-if="editId"
                    path="cancelOrder.cancelNumber"
                  >
                    <NInput
                      v-model:value="form.cancelOrder.cancelNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="注销日期:"
                    path="cancelOrder.cancelDate"
                  >
                    <NDatePicker
                      placeholder="请选择日期"
                      type="date"
                      value-format="yyyy-MM-dd"
                      v-model:formatted-value="form.cancelOrder.cancelDate"
                      :input-readonly="true"
                      class="inputWH"
                      clearable
                    />
                  </NFormItem>
                  <NFormItem
                    label="注销凭证名称:"
                    path="cancelOrder.cancelName"
                  >
                    <NInput
                      v-model:value="form.cancelOrder.cancelName"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="注销批准文号:"
                    path="cancelOrder.docNumber"
                  >
                    <NInput
                      v-model:value="form.cancelOrder.docNumber"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="注销原因:"
                    path="cancelOrder.reason"
                  >
                    <NInput
                      v-model:value="form.cancelOrder.reason"
                      class="inputWH"
                    />
                  </NFormItem>

                  <NFormItem
                    label="备注:"
                    path="cancelOrder.notes"
                  >
                    <NInput
                      v-model:value="form.cancelOrder.notes"
                      class="inputWH"
                    />
                  </NFormItem>
                  <NFormItem
                    label="附件："
                    path="cancelOrder.fileIds"
                  >
                    <UploadFileV2
                      :file-list="form.cancelOrder.fileIdFiles"
                      @update:file-list="(e: any) => handleUpdateFileList(e, 'cancelOrder')"
                    >
                      <template #trigger="{ handleClick }">
                        <n-button
                          @click="handleClick"
                          color="#6CB187"
                          ghost
                          size="small"
                        >
                          点击上传
                        </n-button>
                      </template>
                    </UploadFileV2>
                  </NFormItem>
                </NForm>
              </DetailFormProvider>
            </div>
            <NSpace
              justify="space-between"
              style="margin-top: 20rem"
            >
              <div class="topTitle">藏品信息</div>
              <NSpace>
                <NUpload
                  @update:file-list="handleUploadChange"
                  :show-file-list="false"
                >
                  <NButton
                    type="warning"
                    style="width: 115px"
                    class="btnExport"
                  >
                    模板导入
                  </NButton>
                </NUpload>
                <NButton
                  type="warning"
                  style="width: 115px"
                  class="btnDownload"
                  @click="handleDownload"
                >
                  模板下载
                </NButton>
                <NButton
                  tertiary
                  type="error"
                  style="width: 115px"
                  @click="BatchDelete"
                  v-if="!editId"
                >
                  批量删除
                </NButton>
              </NSpace>
            </NSpace>
            <!-- <div class="link_content" v-if="props?.typeShow != 1">
              <div class="link_item" :key="i.id" v-for="i in configData">
                <img :src="preUrlImg + i.code + '.png'" :onerror="imgDefault" />
                <div>
                  <div style="margin-left: 10rem">{{ i.value }}件</div>
                  <div style="margin-left: 10rem">{{ i.label?.slice(0, 15) }}</div>
                </div>
              </div>
              <NPopover trigger="click" :overlap="false" raw :show-arrow="false" v-if="otherConfigData.length > 0">
                <template #trigger>
                  <div class="link_item" style="justify-content: center; cursor: pointer"
                    v-if="otherConfigData.length > 0">
                    更多
                  </div>
                </template>
                <div class="link_content">
                  <div class="link_item1" v-for="i in otherConfigData" :key="i.id">
                    <img style="height: 35rem" :src="preUrlImg + i.code + '.png'" :onerror="imgDefault" />
                    <div>
                      <div style="margin-left: 10rem">{{ i.value }}件</div>
                      <div style="margin-left: 10rem">{{ i.label?.slice(0, 15) }}</div>
                    </div>
                  </div>
                </div>
              </NPopover>
            </div> -->
            <TableView class="table">
              <template #table="props">
                <NDataTable
                  v-bind="props"
                  :bordered="false"
                  :columns="form.orderTypeCode == 'A3503' ? columns1 : columns"
                  :data="tableData"
                  :rowKey="rowKey"
                  min-height="200"
                  :checked-row-keys="deleteId"
                  @update:checked-row-keys="rowKeysChange"
                />
              </template>
              <template #pagination>
                <NPagination
                  show-size-picker
                  show-quick-jumper
                  :page-sizes="paginationReactive.pageSizes"
                  :item-count="paginationReactive.itemCount"
                  :page="paginationReactive.page"
                  :page-size="paginationReactive.pageSize"
                  @update:page="paginationReactive.onChange"
                  @update:page-size="paginationReactive.onUpdatePageSize"
                  :suffix="() => '页'"
                />
              </template>
            </TableView>

            <NModal
              :auto-focus="false"
              v-model:show="modalVisible"
            >
              <VDialogContent
                @close="modalVisible = false"
                @submit="againDelete"
                title="删除提示"
              >
                <div style="width: 300rem; height: 100rem; text-align: center; line-height: 100rem">
                  您确定要删除吗?
                </div>
              </VDialogContent>
            </NModal>

            <NModal
              :auto-focus="false"
              v-model:show="contactsModalVisible"
              @close="contactsModalVisible = false"
            >
              <VScope
                @close="contactsModalVisible = false"
                @scopeSubmit="handleContactsModalSubmit"
                :default-list=" form.orderTypeCode=='A3502'? form.backOrder.batchReceivers!:form.cleanOrder.batchReceivers!"
                flat
              />
            </NModal>
            <NModal
              :auto-focus="false"
              v-model:show="modalVisiblePosition"
            >
              <VDialogContent
                @close="modalVisiblePosition = false"
                @submit="changePositionName"
                title="请选择库房"
              >
                <NForm
                  :model="form"
                  :rules="formRules"
                  ref="userFormRef"
                  label-placement="left"
                  require-mark-placement="left"
                  label-width="140rem"
                >
                  <NSpace>
                    <NFormItem
                      label="入库位置："
                      path="itemsStaging.firstLevelCode"
                    >
                      <NSelect
                        v-model:value="form.itemsStaging.firstLevelCode"
                        placeholder="位置1"
                        class="inputWHmin"
                        filterable
                        clearable
                        :options="optionInPosition0"
                        @update-value="(e, option) => changeOptionFn(e, 1, option)"
                        :disabled="props?.typeShow == 1"
                      />
                    </NFormItem>
                    <NFormItem
                      label=""
                      path="itemsStaging.secondLevelCode"
                    >
                      <NSelect
                        v-model:value="form.itemsStaging.secondLevelCode"
                        placeholder="位置2"
                        class="inputWHmin"
                        filterable
                        clearable
                        :options="optionInPosition1"
                        @update-value="(e, option) => changeOptionFn(e, 2, option)"
                        :disabled="props?.typeShow == 1"
                      />
                    </NFormItem>
                    <NFormItem
                      label=""
                      path="itemsStaging.threeLevelCode"
                    >
                      <NSelect
                        v-model:value="form.itemsStaging.threeLevelCode"
                        placeholder="位置3"
                        class="inputWHmin"
                        filterable
                        clearable
                        :options="optionInPosition2"
                        @update-value="(e, option) => changeOptionFn(e, 3, option)"
                        :disabled="props?.typeShow == 1"
                      />
                    </NFormItem>
                    <NFormItem
                      label=""
                      path="itemsStaging.fourthLevelCode"
                    >
                      <NSelect
                        v-model:value="form.itemsStaging.fourthLevelCode"
                        placeholder="位置4"
                        class="inputWHmin"
                        filterable
                        clearable
                        :options="optionInPosition3"
                        @update-value="(e, option) => changeOptionFn(e, 4, option)"
                        :disabled="props?.typeShow == 1"
                      />
                    </NFormItem>
                    <NFormItem
                      label=""
                      path="itemsStaging.fifthLevelCode"
                    >
                      <NSelect
                        v-model:value="form.itemsStaging.fifthLevelCode"
                        placeholder="位置5"
                        class="inputWHmin"
                        filterable
                        clearable
                        :options="optionInPosition4"
                        @update-value="(e, option) => changeOptionFn(e, 5, option)"
                        :disabled="props?.typeShow == 1"
                      />
                    </NFormItem>
                    <NFormItem
                      label=""
                      path="itemsStaging.sixthLevelCode"
                    >
                      <NSelect
                        v-model:value="form.itemsStaging.sixthLevelCode"
                        placeholder="位置6"
                        class="inputWHmin"
                        filterable
                        clearable
                        :options="optionInPosition5"
                        @update-value="(e, option) => changeOptionFn(e, 6, option)"
                        :disabled="props?.typeShow == 1"
                      />
                    </NFormItem>
                  </NSpace>
                </NForm>
              </VDialogContent>
            </NModal>
          </div>
        </NSpin>
      </NScrollbar>
    </div>
    <NModal
      :auto-focus="false"
      :mask-closable="false"
      v-model:show="processVisible"
    >
      <n-progress
        type="line"
        style="width: 200px"
        status="success"
        :percentage="percentage"
      >
        {{ percentage }}%
      </n-progress>
    </NModal> 
  <NModal
    :auto-focus="false"
    v-model:show="importErrorModalVisible"
  >
    <VDialogContent
      @close="handleCancelImport"
      @submit="handleExport"
      title="导入提示"
      submit-text="导出错误报告"
      close-text="确定"
      :submitVisible="!isImportSuccess"
    >
      <p style="max-width: 400rem">
        {{ importErrorMessage }}
      </p>
    </VDialogContent>
  </NModal>
  </div>
  <FixedAction>
    <NSpace justify="center">
      <NButton
        style="width: 78px"
        ghost
        @click="goBack"
      >
        {{ !editId ? '取消' : '关闭' }}
      </NButton>
      <NButton
        type="primary"
        style="width: 78px"
        @click="submit"
        :loading="loading"
        v-if="!editId"
      >
        确定
      </NButton>
    </NSpace>
  </FixedAction>
</template>
<style scoped lang="scss">
@mixin CommonFont {
  font-size: 15rem;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  color: #333333;
}

.main {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;

  .bd-card {
    padding: 20rem;
    background-color: #e1e1e1;
    display: flex;
    flex-wrap: wrap;
  }

  .link_content {
    width: 100%;
    display: flex;
    margin-bottom: 10rem;

    .link_item {
      width: 185rem;
      height: 68rem;
      background: #e6e6e6;
      border-radius: 6rem;
      border: 1rem solid #ececec;
      display: flex;
      align-items: center;
      padding-left: 5rem;
      text-decoration: none;
      color: initial;

      img {
        display: block;
        width: 35rem;
        height: 35rem;
        border-radius: 50%;
      }
    }
  }

  .link_item {
    width: 175rem;
    height: 68rem;
    background: #e6e6e6;
    border-radius: 6rem;
    border: 1rem solid #ececec;
    display: flex;
    align-items: center;
    padding-left: 5rem;
    text-decoration: none;
    color: initial;
  }

  img {
    display: block;
    width: 35rem;
    height: 35rem;
    border-radius: 50%;
  }

  .form_content {
    width: 100%;
    height: 100%;
    padding: 20rem 20rem 0;

    .topTitle {
      font-size: 22px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      color: #5fb17f;
      margin-bottom: 10rem;
    }

    .inputWH {
      width: 300rem;
    }

    .inputWHmin {
      width: 150rem;
    }

    .content {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 100%;
      padding: 18rem 33rem 120rem;
      overflow-y: scroll;
      background-color: #ebeceb;
      @include CommonFont;
    }
  }

  .approve {
    display: flex;
    width: 100%;
    margin-bottom: 20rem;
    border-bottom: 1px dashed #bc9e70;

    .box {
      display: flex;
      flex-direction: column;
      justify-content: center;
      min-width: 100rem;
      width: auto;
      height: 90rem;
      border-radius: 4px;
      border: 1px solid #d9d9d9;
      padding: 12rem;
      margin-right: 10rem;
      margin-bottom: 20rem;

      span:first-child {
        font-size: 16rem;
      }

      span:last-child {
        font-weight: 500;
        color: #5fb17f;
      }
    }
  }

  .link_item2 {
    width: 155rem;
    height: 68rem;
    background: #e6e6e6;
    border-radius: 6rem;
    border: 1rem solid #ececec;
    display: flex;
    align-items: center;
    padding-left: 5rem;
    text-decoration: none;
    color: initial;
  }
}
.progressHint {
  display: flex;
  width: 100%;
  padding: 5px 15px;
}
.link_item1 {
  width: 185rem;
  height: 68rem;
  background: #e6e6e6;
  border-radius: 6rem;
  border: 1rem solid #ececec;
  display: flex;
  align-items: center;
  padding-left: 5rem;
  text-decoration: none;
  color: initial;
}

//流程样式
.progress {
  width: 100%;
  min-height: 50rem;
  background-color: #d5e2d8;
  border-radius: 5rem;
  padding: 10rem;
  display: flex;
  align-items: center;
  margin-top: 10rem;
}

.iconStyle {
  margin-right: 5rem;
  color: #5fb17f;
}

.content::-webkit-scrollbar {
  display: none;
}
.contacts {
  display: flex;
  flex-direction: column;
  gap: 10rem 0;
  .n-button {
    max-width: 126rem;
  }

  .contacts-content {
    display: grid;
    grid-template-columns: repeat(3, auto);
    gap: 10rem;
    padding: 15rem;
    background-color: #fff;
  }
}
:deep(.n-spin-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-content) {
  width: 100%;
  height: 100%;
}

:deep(.n-spin-content) {
  width: 100%;
  height: 100%;
}
</style>
